package com.baicai.componentdatadeliver;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

/**
 * Create By：bai_cai，on 2019/1/16
 * God bless my code!
 */
public class LoginActivity extends Activity {

    private EditText mUserName;
    private EditText mUsrPassword;
    private Button mRegisterBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_login);

        initView();

        initListener();
    }

    private void initListener() {
        mRegisterBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                handlerRegister();
            }
        });
    }

    private void handlerRegister() {
        String userNameText = mUserName.getText().toString().trim();
        String userPasswordText = mUsrPassword.getText().toString().trim();
        if (TextUtils.isEmpty(userNameText) | TextUtils.isEmpty(userPasswordText)) {
            Toast.makeText(this, "用户名或者密码为空", Toast.LENGTH_SHORT).show();
        } else {
            Intent intent = new Intent(this, RegisterResultActivity.class);
            intent.putExtra("username", userNameText);
            intent.putExtra("password", userPasswordText);
            startActivity(intent);
        }
    }

    private void initView() {

        mUserName = this.findViewById(R.id.user_name_et);
        mUsrPassword = this.findViewById(R.id.password_et);
        mRegisterBtn = this.findViewById(R.id.register_btn);
    }
}
